import { Component, OnInit } from '@angular/core';
import {TipService} from "../../../services/tip.service";
import {ExtendHttpService} from "../../../services/extend-http.service";
import {ActivatedRoute, CanActivate, Router} from "@angular/router";

@Component({
  selector: 'app-notice-detail',
  templateUrl: './notice-detail.component.html',
  styleUrls: ['./notice-detail.component.css']
})
export class NoticeDetailComponent implements OnInit {

  id = '';
  content = '';
  tipType = 'error';

  notice = {
    title:'',// 标题
    content:'',// 内容
    create_time:''// 创建时间
  }
  constructor(
    private tipService: TipService,
    private extendHttp: ExtendHttpService,
    private router: Router,
    private activatedRoute: ActivatedRoute
  ) { }

  ngOnInit() {
    cBack =()=> {
      $('#btn-back').trigger('click');
    }

    this.activatedRoute.queryParams.subscribe(res => {
      this.id = res['id'];
    })

    this.getData();
  }

  getData() {
    this.extendHttp.get('/agentApp/notice/getDetail', {id: this.id}).subscribe(response => {
      let res = response.json();
      if (res['code'] === '0') {
        this.notice = res['notice'];
      } else if (res['code'] == '-2001') {
        this.tipType = 'error';
        this.tipService.change(true, res['message']);
        setTimeout(() => {
          this.router.navigate(['/login']);
        }, 1500);
      } else {
        this.tipType = 'error';
        this.tipService.change(true, res['message']);
      }
    }, error => {
      this.tipType = 'error';
      this.tipService.change(true, '系统繁忙，操作失败！');
    });
  }

}
